app.controller("login", function ($http, $scope, $location) {

    $scope.user = JSON.parse(sessionStorage.getItem("user"));
    console.log($scope.user);
    $scope.userName = null;
    $scope.userPassword = null;

    $scope.loginAdmin = function () {

        var loginAdmin = {'adminName': $scope.userName, 'adminPassword': $scope.userPassword};
        if ($scope.userPassword != null && $scope.userName != null) {

            $http({
                method: 'POST',
                url:app.url+ '/login/admin',
                data: loginAdmin
            }).then(function (res) {
                if (res.data.adminId!= null) {
                    app.user=res.data;
                    sessionStorage.setItem("user",JSON.stringify(app.user));
                    $location.path("/index-content");


                } else {
                    $("#modal-191634").click();
                    $('.modal-title').html("登录失败");
                    $('.modal-body').html("未找到您的相关信息,请检查您的信息是否填写有误");
                }
            }, function () {
                $("#modal-191634").click();
                $('.modal-title').html("登录失败");
                $('.modal-body').html("服务器响应超时");
            })
        }else {
            $("#modal-191634").click();
            $('.modal-title').html("信息不完整");
            $('.modal-body').html("账号或密码未输入完整")
        }


    };
    $scope.loginStudent = function () {

        var loginStudnt = {'studentName': $scope.userName, 'studentPassword': $scope.userPassword};
        if ($scope.userPassword != null && $scope.userName != null) {

            $http({
                method: 'POST',
                url:app.url+ '/login/student',
                data: loginStudnt
            }).then(function (res) {

                if (res.data.studentId!= null) {
                    app.user=res.data;
                    sessionStorage.setItem("user",JSON.stringify(app.user));
                    console.log(app.user);
                    $location.path("/index-content");

                } else {
                    $("#modal-191634").click();
                    $('.modal-title').html("登录失败");
                    $('.modal-body').html("未找到您的相关信息,请检查您的信息是否填写有误");
                }
            }, function () {
                console.log();
                $("#modal-191634").click();
                $('.modal-title').html("登录失败");
                $('.modal-body').html("服务器响应超时");
            })
        }else {
            $("#modal-191634").click();
            $('.modal-title').html("信息不完整");
            $('.modal-body').html("账号或密码未输入完整")
        }


    }
});
